package com.manopservice.service;

import com.manopservice.model.UploadFiles;

import java.io.File;
import java.io.FileOutputStream;
import javax.servlet.ServletContext;

import org.springframework.stereotype.Service;


@Service("UploadFilesService")
public class UploadFilesServiceImpl implements UploadFilesService {

	
	@Override
	public String uploadImages(UploadFiles uploadDetails, ServletContext context, String resource) {
			
	          FileOutputStream outputStream = null;
	          String filePath = context.getRealPath("/") + resource + uploadDetails.getFileData().getOriginalFilename();
	          try {
	              outputStream = new FileOutputStream(new File(filePath));
	              outputStream.write(uploadDetails.getFileData().getFileItem().get());
	              outputStream.close();
	              System.out.println("Path of Images: "+filePath);
	          } catch (Exception e) {
	              System.out.println("Error while saving file !!!");
	             
	          }
	          return uploadDetails.getFileData().getOriginalFilename();
	}
	
	

}
